<%@ include file="/WEB-INF/jsp/common/include.jsp" %>
<%@ page pageEncoding="UTF-8"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<%@ taglib prefix="app" uri="AppTags" %>
<tiles:insertDefinition name="layout.tiles">
  <tiles:putAttribute name="pageTitle">Сдам квартиру <c:out value="${flatAd.street}"/>, <c:out value="${flatAd.building}"/></tiles:putAttribute>
  <tiles:putAttribute name="searchTab" value="selected"/>
  <tiles:putAttribute name="body">
    <script type="text/javascript" src="<app:slaveServerUrl />/js/bac/common.js"></script>
    <script>
      if(readCookie('showUserReviewThankYou') == 'true'){
        alert('Спасибо за отзыв. Ваш отзыв будет рассмотрен в ближайшее время.');
      }
      eraseCookie('showUserReviewThankYou');
    </script>
    <div id="list">
      <tiles:insertDefinition name="adContent.tiles">
        <tiles:putAttribute name="images">
          <center>
            <c:if test="${flatAd.lat != null}">
              <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
              <script src="http://www.openstreetmap.org/openlayers/OpenStreetMap.js"></script>
              <p id="osmDiv" style="width:500px; height: 500px">
              </p>
              <script>
                var map = new OpenLayers.Map('osmDiv',
                    { maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),
                      numZoomLevels: 19,
                      maxResolution: 156543.0399,
                      units: 'm',
                      projection: new OpenLayers.Projection("EPSG:900913"),
                      displayProjection: new OpenLayers.Projection("EPSG:4326")
                    });

                var layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");

                map.addLayers([layerMapnik]);

                var markers = new OpenLayers.Layer.Markers( "Markers" );
                map.addLayer(markers);
                var fromProjection = new OpenLayers.Projection("EPSG:4326");   // Transform from WGS 1984
                var toProjection   = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
                var position       = new OpenLayers.LonLat(${flatAd.lon}, ${flatAd.lat}).transform( fromProjection, toProjection);
                var size = new OpenLayers.Size(21,25);
                var offset = new OpenLayers.Pixel(-(size.w/2), -(size.h / 2));
                var icon = new OpenLayers.Icon('/image/map/${flatAd.agent ? 'agent' : 'owner'}-map.png', size, offset);
                markers.addMarker(new OpenLayers.Marker(position, icon));

                var lonLat = new OpenLayers.LonLat(27.555, 53.902).transform(map.displayProjection,  map.projection);
                map.setCenter (lonLat, 11);
              </script>
            </c:if>
            <c:forEach var="flatImage" items="${flatAd.flatImages}">
              <p>
                <script>
                  document.write('<img src="/ad/image/serve/image.do' + '?flatImageId=${flatImage.id}" />');
                </script>
              </p>
            </c:forEach>
          </center>
        </tiles:putAttribute>
      </tiles:insertDefinition>
    </div>
    <div class="box-container" style="background: white; border-radius: 10px; margin-bottom: 22px; padding-bottom: 20px">
      <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
      <!-- hatuby-details -->
      <ins class="adsbygoogle"
           style="display:inline-block;width:728px;height:90px"
           data-ad-client="ca-pub-2127591047178376"
           data-ad-slot="9308285842"></ins>
      <script>
        (adsbygoogle = window.adsbygoogle || []).push({});
      </script>
    </div>
  </tiles:putAttribute>
</tiles:insertDefinition>